﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NFinal
{
    /// <summary>
    /// 缓存类型
    /// </summary>
    public enum CacheType
    {
        Session,
        DataBase,
        Global
    }
    /// <summary>
    /// 缓存接口
    /// </summary>
    public interface ICache
    {
         void Set(string key, object value, int minutes);
         object Get(string key);
    }
    /// <summary>
    /// 内存缓存
    /// </summary>
    public class Cache:ICache
    {
        private int minutes = 30;
        public Cache()
        { }
        public Cache(int minutes)
        {
            this.minutes = minutes;
        }
        public object Get(string key)
        {
            return System.Runtime.Caching.MemoryCache.Default.Get(key);
        }
        public void Set(string key, object value, int minutes)
        {
            System.Runtime.Caching.MemoryCache.Default.Set(key, value, DateTimeOffset.Now.AddMinutes(minutes));
        }
        public void Set(string key, object value)
        {
            Set(key, value, minutes);
        }
    }
}
